﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using System.Collections.Generic;
using System.ComponentModel;

namespace EyFramework.Library.Select
{
    /**
     * 输入器的基类，超过3个列建议使用此输入器
     */

    [DXToolboxItem(true)]
    public class BaseSearchLookUpEdit : SearchLookUpEdit
    {
        // private List<SeachColumn> columns = null;

        //字段值
        private string _strId = string.Empty;

        private string _strDisplay = string.Empty;

        public BaseSearchLookUpEdit()
        {
        }

        public string StrId
        {
            get
            {
                if (this.EditValue != null)
                {
                    _strId = this.EditValue.ToString();
                }
                else
                {
                    _strId = string.Empty;
                }

                return _strId;
            }
        }

        public string StrDisplay
        {
            get
            {
                _strDisplay = this.Text;
                return _strDisplay;
            }
        }

        public void InitData(List<object> data, List<SeachColumn> columns)
        {
            base.Properties.DataSource = null;
            if (data != null)
            {
                base.Properties.DataSource = data;
            }
            base.Properties.View.Columns.Clear();//清空列
            //循环添加列
            foreach (SeachColumn sc in columns)
            {
                //ID列
                if (sc.ColType == SEARCHCOLUMNTYPE.ID)
                {
                    this.Properties.ValueMember = sc.ColCode;
                    GridColumn columnID = this.Properties.View.Columns.AddField(sc.ColCode);
                    columnID.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    columnID.Caption = sc.ColName;
                    columnID.Visible = sc.ColShow;
                }
                //显示列
                if (sc.ColType == SEARCHCOLUMNTYPE.DISPLAY)
                {
                    this.Properties.DisplayMember = sc.ColCode;
                    GridColumn columnName = this.Properties.View.Columns.AddField(sc.ColCode);
                    columnName.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    columnName.Caption = sc.ColName;
                    columnName.Visible = sc.ColShow;
                }
                //其它列
                if (sc.ColType == SEARCHCOLUMNTYPE.COL)
                {
                    GridColumn columnCol = this.Properties.View.Columns.AddField(sc.ColCode);
                    columnCol.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    columnCol.Caption = sc.ColName;
                    columnCol.Visible = sc.ColShow;
                }
            }
        }
    }
}